package com.zhongwang.business.module.contractManage.service;

import com.zhongwang.business.gen.entity.User;
import com.zhongwang.business.module.basic.model.SysUserModel;
import com.zhongwang.business.module.contractManage.dao.ContractDao;
import com.zhongwang.business.module.contractManage.model.ConContractMainModel;
import com.zhongwang.business.module.contractManage.model.ContractModel;
import com.zhongwang.business.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ContractService {
    @Autowired
    private ContractDao contractDao;

    /**
     * 待签合同列表
     * @param model
     * @return
     */
   public List<ContractModel> unContractList(ContractModel model){
//       User user = ShiroUtils.getUser();
//       model.setCreateName(user.getName());
//       if("admin".equals(user.getAccount())){
//           model.setCreateName(null);
//       }
       List<ContractModel> list=contractDao.unContractList(model);

       int m = list.size();
       for (int i = 0; i < m; i++) {
           ContractModel model1=new ContractModel();
           List<ContractModel> subList=contractDao.selectProjectById(list.get(i).getQuoteId());
           /**
            * 循环项目名称
            */
           String name="";
           for (int k= 0; k < subList.size(); k++) {
               name=name+subList.get(k).getName()+"</br>";
           }
           list.get(i).setName(name);
           /**
            * 循环项目编号
            */
           String code="";
           for (int k= 0; k < subList.size(); k++) {
               code=code+subList.get(k).getCode()+"</br>";
           }
           list.get(i).setContName(code);
       }
       return list;
   }


    /**
     * 待提交同列表
     * @param model
     * @return
     */
    public List<ConContractMainModel> unContractSubList(ConContractMainModel model){
        /**
         * 待提交列表只显示，自己创建的。
         */
        User user = ShiroUtils.getUser();
        model.setCreateUser(user.getName());

        if("admin".equals(user.getAccount())){
            model.setCreateUser(null);
        }
        List<ConContractMainModel> list=contractDao.unContractSubList(model);

        int m = list.size();
        for (int i = 0; i < m; i++) {
            ContractModel model1=new ContractModel();
            List<ContractModel> subList=contractDao.selectProjectById(list.get(i).getFkId());
            /**
             * 循环项目名称
             */
            String name="";
            String contName="";
            for (int k= 0; k < subList.size(); k++) {
                name=name+subList.get(k).getName()+"</br>";
                contName=contName+subList.get(k).getCode()+"</br>";
            }
            list.get(i).setName(name);
            list.get(i).setContName(contName);
        }
        return list;
    }
}
